package com.mengshu.mybatisplus.properties;

import com.mengshu.token.api.LoginService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Optional;

/**
 * <p>
 *     mybatisplus配置
 * </p>
 *
 * @author liuning
 * @date 10:28 下午 2022/1/31
 */
@Getter
@Setter
@ConfigurationProperties(prefix = MybatisplusProperties.PREFIX)
public class MybatisplusProperties {

    public static final String PREFIX = "mengshu.mybatisplus";

    /**
     * 是否需要登录 默认需要
     */
    private boolean loginRequired = true;

    public void check(Optional<LoginService> loginApi) throws Throwable {
        if (loginRequired) {
            if (!loginApi.isPresent()) {
                throw new Throwable("必须实现LoginApi接口");
            }
        }
    }
}
